//
//  WKUITabBarController.m
//  iBook
//
//  Created by wangjing on 14/12/3.
//  Copyright (c) 2014年 wikiflyer. All rights reserved.
//

#import "WKUITabBarController.h"
#import "PurchViewController.h"
#import "SearchViewController.h"
#import "ChartViewController.h"
#import "FeatureViewController.h"
#import "BookViewController.h"
#import "WKNavigationController.h"

@interface WKUITabBarController ()

@end

@implementation WKUITabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    //添加五个控制器
    BookViewController *bookVC = [[BookViewController alloc]init];
    FeatureViewController *featureVC = [[FeatureViewController alloc]init];
    ChartViewController *chartVC = [[ChartViewController alloc]init];
    SearchViewController *searchVC = [[SearchViewController alloc]init];
    PurchViewController *purchVC = [[PurchViewController alloc]init];
    [self addOneChildVC:bookVC title:@"My Books" imageName:@"tab1" selectedImageName:@"tab1_sel"];
    [self addOneChildVC:featureVC title:@"Featured" imageName:@"tab2" selectedImageName:@"tab2_sel"];
    [self addOneChildVC:chartVC title:@"Top Charts" imageName:@"tab3" selectedImageName:@"tab3_sel"];
    [self addOneChildVC:searchVC title:@"Search" imageName:@"tab4" selectedImageName:@"tab4_sel"];
    [self addOneChildVC:purchVC title:@"Purchased" imageName:@"tab5" selectedImageName:@"tab5_sel"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)addOneChildVC:(UIViewController *)childViewController title:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName{
    
    childViewController.title = title;
    childViewController.tabBarItem.image = [UIImage imageNamed:imageName];
    
    UIImage *selectedImage = [UIImage imageNamed:selectedImageName];
    childViewController.tabBarItem.selectedImage = selectedImage;
    
    WKNavigationController *nav = [[WKNavigationController alloc]initWithRootViewController:childViewController];
    
    [self addChildViewController:nav];
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
